package com.qfedu.buy.server.controller;

import com.qfedu.buy.common.config.SystemConfig;
import com.qfedu.buy.common.dto.CartAddDto;
import com.qfedu.buy.common.dto.CartNumDto;
import com.qfedu.buy.common.vo.R;
import com.qfedu.buy.server.service.intf.CartItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: NeighborBuy
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-02-02 09:38
 */
@RestController
@RequestMapping("server/cart/")
public class CartItemController {
    @Autowired
    private CartItemService itemService;

    //
    @PostMapping("/addcartd.do")
    public R add(@RequestBody CartAddDto dto, HttpServletRequest request){
        return itemService.addCart(dto,request.getIntHeader(SystemConfig.USER_ID));
    }
    @PutMapping("/changenum.do")
    public R change(@RequestBody CartNumDto dto,HttpServletRequest request){
        return itemService.changeNumV2(dto,request.getIntHeader(SystemConfig.USER_ID));
    }
    @GetMapping("/list.do")
    public R all(HttpServletRequest request){
        return itemService.queryByUid(request.getIntHeader(SystemConfig.USER_ID));
    }
    @DeleteMapping("/del.do")
    public R del(@RequestParam int cid){
        return itemService.del(cid);
    }

}
